<template>
	<view>
		<!-- 保证金缴纳 -->
		<view class="mainpadding_top">
			<view class="margin_top flexcolumn">
				<view class="titletext hei_text bold">实付金额</view>
				<view class="margin_top6 hei_text bold" style="font-size: 60rpx;">{{pay_price}}</view>
			</view>
			<view class="mainpadding_top  margin_top6 ffffff radius">
				<view class="flexbetween" @click="pay_type=10">
					<view class="flexleft">
						<u-icon name="weixin-circle-fill" color="#26db6f" size="28"></u-icon>
						<view class="titletext hei_text margin_left">微信</view>
					</view>
					<u-icon name="checkmark-circle-fill" v-show="pay_type==10" color="#ff8505" size="24"></u-icon>
					<u-icon name="checkmark-circle-fill" v-show="pay_type!=10" color="#999" size="24"></u-icon>
				</view>
				<view class="margin_top5 flexbetween" @click="pay_type=20">
					<view class="flexleft">
						<u-icon name="zhifubao-circle-fill" color="#55aaff" size="28"></u-icon>
						<view class="titletext hei_text margin_left">支付宝</view>
					</view>
					<u-icon name="checkmark-circle-fill" v-show="pay_type==20" color="#ff8505" size="24"></u-icon>
					<u-icon name="checkmark-circle-fill" v-show="pay_type!=20" color="#999" size="24"></u-icon>
				</view>
			</view>

		</view>
		<view class="mainpadding gudingdb">
			<view class="bigbtn" @click="baozhengjinPay()" v-if="type==2">立即充值</view>
			<view class="bigbtn" @click="jifencz()" v-if="type==3">立即充值</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				pay_price: "",
				type: 1, //1积分商品支付，2保证金缴纳,3积分充值
				userInfo: {},
				order_id: "",
				pay_type: 10
			}
		},
		onLoad(options) {
			let data = JSON.parse(decodeURIComponent(options.msg))
			this.pay_price = data.pay_price
			this.type = data.type
			this.order_id = data.order_id
		},
		methods: {
			baozhengjinPay() {
				httpRequest.request('/api/Rechargecl/rechargeMoney', 'POST', {
					pay_type: this.pay_type,
					price: this.pay_price,
					type: 2,
				}).then(res => {
					if (res.code == 1) {
						if (this.pay_type == 10) { //微信
							uni.requestPayment({
								provider: 'wxpay',
								orderInfo: res.data.wxconfig, //后台返回的支付数据
								success: function(res) {
									uni.navigateBack(1)
								},
								fail: function(err) {
									console.log(err)
								}
							});
						} else { //支付宝
							uni.requestPayment({
								provider: 'alipay',
								orderInfo: res.data.wxconfig, //后台返回的支付数据
								success: function(res) {
									uni.navigateBack(1)
								},
								fail: function(err) {
									console.log(err)
								}
							});
						}
					} else {
						httpRequest.toast(res.msg)
					}
				})
			},
			jifencz() {
				httpRequest.request('/api/Rechargecl/rechargeMoney', 'POST', {
					pay_type: this.pay_type,
					price: this.pay_price,
					type: 1,
				}).then(res => {
					if (res.code == 1) {
						if (this.pay_type == 10) { //微信
							uni.requestPayment({
								provider: 'wxpay',
								orderInfo: res.data.appconfig, //后台返回的支付数据
								success: function(res) {
									uni.navigateBack(1)
								},
								fail: function(err) {
									console.log(err)
								}
							});
						} else { //支付宝
							uni.requestPayment({
								provider: 'alipay',
								orderInfo: res.data.appconfig, //后台返回的支付数据
								success: function(res) {
									uni.navigateBack(1)
								},
								fail: function(err) {
									console.log(err)
								}
							});
						}
					} else {
						httpRequest.toast(res.msg)
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.iconclass {
		width: 40rpx;
		height: 40rpx;
	}
</style>